package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-18
 * @Description:
 * @Version: 1.0
 */
@Tag(name = "租期管理")
@RequestMapping("/admin/term")
@RestController
public class LeaseTermController{
    @Autowired
    private LeaseTermService leaseTermService;

    //查询租期列表
    @GetMapping("list")
    @Operation(summary = "查询全部租期列表")
    public Result<List<LeaseTerm>> list(){
        List<LeaseTerm> list = leaseTermService.list();
        return Result.ok(list);
    }

    //保存或更新租期信息
    @PostMapping("saveOrUpdate")
    @Operation(summary = "保存或更新租期信息")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm){
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok();
    }

    //根据id删除租期信息
    @DeleteMapping("deleteById")
    @Operation(summary = "根据ID删除租期")
    public Result deleteById(@RequestParam Long id){
        leaseTermService.removeById(id);
        return Result.ok();
    }
}
